import Vue from 'vue';
import VueRouter from 'vue-router';
// 使用
Vue.use(VueRouter);

import Home from '@/views/home/home';
import Category from '@/views/category/category';
import Find from '@/views/find/find';
import Cart from '@/views/cart/cart';
import Mine from '@/views/mine/mine';

// 配置路由规则
// 首次进入页面就加载
var routes = [{
    path: '/',
    redirect: '/home'
}, {
    path: '/home',
    component: Home,
    meta: { showTabbar: true }
}, {
    path: '/category',
    component: Category,
    meta: { showTabbar: true }
}, {
    path: '/find',
    component: Find,
    meta: { showTabbar: true }
}, {
    path: '/cart',
    component: Cart,
    meta: { showTabbar: true }
}, {
    path: '/mine',
    component: Mine,
    meta: { showTabbar: true }
}, {
    // 路由懒加载--按需进行引入
    path: '/search',
    component: () =>
        import ('../views/search/search.vue'),
    meta: { showTabbar: true }
}, {
    // 路由懒加载--按需进行引入
    path: '/login',
    component: () =>
        import ('../views/login/login.vue'),
    meta: { showTabbar: false }
}, {
    // 路由懒加载--按需进行引入
    path: '/goodslist/:cat_id',
    component: () =>
        import ('../views/goodslist/goodslist.vue'),
    meta: { showTabbar: false }
}, {
    // 路由懒加载--按需进行引入
    path: '/details/:goods_id',
    component: () =>
        import ('../views/details/details.vue'),
    meta: { showTabbar: false }
}];

// 创建router的实例
var router = new VueRouter({
    routes,
    scrollBehavior(to, from, saveTop) {
        console.log(to);
        console.log(from);
        console.log(saveTop);
        if (saveTop) {
            return saveTop
        } else {
            return { x: 0, y: 0 }
        }
    }
});

export default router;